<!--
 * @Description:
 * @Author: zheng yiliang
 * @Date: 2021-06-06 13:30:51
 * @LastEditTime: 2021-06-06 17:36:12
 * @LastEditors: zheng yiliang
-->

<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="创建时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          class="mgr10"
        ></el-date-picker>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row type="flex">
      <el-col> </el-col>
      <el-col class="tr">
        <right-toolbar
          :show-search.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-col>
    </el-row>

    <el-table class="mgt10" v-loading="loading" :data="qqList">
      <el-table-column type="index" width="50" label="#"></el-table-column>
      <el-table-column
        prop="IP"
        label="IP"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="IP_Source"
        label="IP来源"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column prop="plate" label="平台"></el-table-column>
      <el-table-column prop="browser" label="浏览器"></el-table-column>
      <el-table-column prop="actions" label="用户行为"></el-table-column>
      <el-table-column label="创建时间" align="center" prop="create_time">
        <template slot-scope="scope">
          <span>{{ scope.row.create_time | formatDate }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <el-pagination
      background
      :current-page="queryParams.pagenum"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="queryParams.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
  </div>
</template>

<script>
import { visiLog } from '@/api'
import RightToolbar from '@/components/RightToolbar'
export default {
  name: 'VisiLog',
  components: { RightToolbar },
  data() {
    return {
      total: 0,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 菜单表格树数据
      qqList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        dateRange: [],
        pagenum: 1,
        pagesize: 5
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询菜单列表 */
    async getList() {
      this.loading = true
      const { _RejCode, data } = await visiLog(this.queryParams).catch(
        (err) => err
      )
      if (_RejCode !== '00000000') {
        this.total = 0
        this.qqList = []
        this.loading = false
        return
      }
      this.qqList = data.list
      this.total = data.count
      this.loading = false
    },
    // 一页显示多少条数据
    handleSizeChange(pageSize) {
      this.queryParams.pagesize = pageSize
      this.queryParams.pagenum = 1
      this.getList()
    },
    // 当前页数，当前在第几页
    handleCurrentChange(curPage) {
      this.queryParams.pagenum = curPage
      this.getList()
    },
    // 表单重置
    async reset() {
      await this.$nextTick()
      // 表单参数
      this.form = {}
      this.$refs['form'].resetFields()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs['queryForm'].resetFields()
      this.handleQuery()
    }
  }
}
</script>
